import Vue from 'vue';
import Vuex from 'vuex';
import getters from './getters';
import app from './modules/app';
import permission from './modules/permission';
import settings from './modules/settings';
import user from './modules/user';
import tagsView from './modules/tagsView';

import conversation from './modules/conversation';
import group from './modules/group';
import video from './modules/video';
import friend from './modules/friend';
import blacklist from './modules/blacklist';
import { Message } from 'element-ui';

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    current: Date.now(), // 当前时间
    intervalID: 0,
    message: undefined
  },
  mutations: {
    startComputeCurrent(state) {
      state.intervalID = setInterval(() => {
        state.current = Date.now();
      }, 500);
    },
    stopComputeCurrent(state) {
      clearInterval(state.intervalID);
      state.intervalID = 0;
    },
    showMessage(state, options) {
      if (state.message) {
        state.message.close();
      }
      state.message = Message({
        message: options.message,
        type: options.type || 'success',
        duration: options.duration || 2000,
        offset: 40
      });
    }
  },
  modules: {
    app,
    permission,
    settings,
    tagsView,

    conversation,
    group,
    friend,
    blacklist,
    user,
    video
  },
  getters
});

export default store;
